import axios from 'axios';
import { POINT_CONVERSION_COMPRESSED } from 'constants';

const book = {
    state: {
        novel: [],
        reality: [],
        travel: [],
        bookTags: [

        ]
    },

    mutations: {
        getBook (state, payload){
            switch (payload.tag) {
                case 'novel':
                    state.novel = payload.result;
                    break;
                case 'reality':
                    state.reality = payload.result;
                    break;
                case 'travel':
                    state.travel = payload.result;
                    break;
                default: 
                    break;
            }
        }
    },

    actions: {
        getBook ({commit, state}) {
            axios.post('/v2/book/search', {
                q: '虚构类',
                count: 8
            })
            .then(function(result) {
                console.log('小说->', result);
                commit('getBook', {
                    tag: 'novel',
                    result: result.data
                })
            })
            .catch(function(err){
                console.log(err);
            })

            axios.post('/v2/book/search', {
                q: '非虚构类',
                count: 8
            }).then(function(result){
                console.log('非虚构类->', result);
                commit('getBook', {
                    tag: 'reality',
                    result: result.data
                })
            }).catch(function(err){
                console.log(err);
            })

            axios.post('v2/book/search', {
                q: '旅行',
                count: 8
            }).then(function(result) {
                console.log('旅游类->', result);
                commit('getBook', {
                    tag: 'travel',
                    result: result.data
                })
            }).catch(function(err){
                console.log(err);
            })
        }
    },

    getters: {
        
    }
}

export default book;